import 'package:shared_preferences/shared_preferences.dart';

import '../common/storage_key.dart';
import '../utils/storage_util.dart';

class User {
  // Obtain shared preferences.
  User._();
  static Future<SharedPreferences> sp() async {
    return await SharedPreferences.getInstance();
  }

  static void setToken(String? tokenValue) {
    StorageUtil().set(StorageKey.token ?? "", tokenValue);
  }

  static void clearToken() {
    setToken("");
  }

  static void setID(num? iDValue) {
    StorageUtil().set(StorageKey.userId ?? "", iDValue.toString());
  }

  static Future getUserID() {
    return StorageUtil().get(StorageKey.userId);
  }

  static Future getToken() {
    return StorageUtil().get(StorageKey.token);
  }

  static void setUserName(String? name) {
    StorageUtil().set(StorageKey.userName ?? "", name);
  }

  static Future getUserName() {
    return StorageUtil().get(StorageKey.userName);
  }

  static void setUserAvatar(String? avatar) {
    StorageUtil().set(StorageKey.userAvatar ?? "", avatar);
  }

  static Future getUserAvatar() {
    return StorageUtil().get(StorageKey.userAvatar);
  }

  static void setUserDepartment(String? department) {
    StorageUtil().set(StorageKey.userDepartment ?? "", department);
  }

  static Future getUserDepartment() {
    return StorageUtil().get(StorageKey.userDepartment);
  }

  static void setUserArea(String? area) {
    StorageUtil().set(StorageKey.userArea ?? "", area);
  }

  static Future getUserArea() {
    return StorageUtil().get(StorageKey.userArea);
  }

  static void setUserPosition(String? position) {
    StorageUtil().set(StorageKey.userPosition ?? "", position);
  }

  static Future getUserPosition() {
    return StorageUtil().get(StorageKey.userPosition);
  }

  static void setUserFollow(String? follow) {
    StorageUtil().set(StorageKey.userFollow ?? "", follow);
  }

  static Future getUserFollow() {
    return StorageUtil().get(StorageKey.userFollow);
  }

  static void setUserPhone(String? phone) {
    StorageUtil().set(StorageKey.userPhone ?? "", phone);
  }

  static Future getUserPhone() {
    return StorageUtil().get(StorageKey.userPhone);
  }

  // static void saveUserBean(String? userBean) {
  //   StorageUtil().set(StorageKey.userBean ?? "", userBean);
  // }
  //
  // static Future getUserBean() {
  //   return StorageUtil().get(StorageKey.userBean);
  // }

  static void setHXName(String? hxname) {
    StorageUtil().set(StorageKey.hxname ?? "", hxname);
  }

  static Future getHXName() {
    return StorageUtil().get(StorageKey.hxname);
  }

  static void setHXPasswd(String? hxpasswd) {
    StorageUtil().set(StorageKey.hxpasswd ?? "", hxpasswd);
  }

  static Future getHXPasswd() {
    return StorageUtil().get(StorageKey.hxpasswd);
  }

  /// 保存客服电话
  static void setSericePhone(String phone) {
    StorageUtil().set(StorageKey.servicePhone, phone);
  }

  /// 获取客服电话
  static Future getSericePhone() {
    return StorageUtil().get(StorageKey.servicePhone);
  }
}
